<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮播图</title>
    <style>
        *{
            padding:0;
            margin:0;
        }
        ul{
            list-style: none;
        }
        img {
            vertical-align: top;
            width: 100%;
            height: 100%;
        }

        .box {
            width: 500px;
            height: 350px;
            padding: 10px;
            margin:100px auto;
            background-color: orange;
            border-radius: 5px;
            position: relative;
        }
        
        .slider {
            width: 500px;
            height: 350px;
            background-color: #369;
            overflow: hidden;
        }

        .slider ul{
            width:400%;
            overflow: hidden;
            position: relative;
            top: 0;
            left: 0;
        }

        .slider li{
            width: 500px;
            height: 350px;
            float: left;
        }

        .point {
            position: absolute;
            bottom: 15px;
            left: 50%;
        }

        .point span {
            display: inline-block;
            margin-right: 5px;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #3e3e3e;
            color: white;
            line-height: 20px;
            text-align: center;
            cursor: pointer;
            font-family: 'Arial', "Microsoft YaHei UI";
        }

        .point span.current {
            background-color: orange;
        }

        .point span.uncurrent {
            background-color: #3e3e3e;
        }
    </style>
    <script>
        window.onload = function () {
            //生成小圆点
            var lis = document.getElementsByTagName("li");
            var point = document.getElementsByClassName("point")[0];
            for (var i = 0; i < lis.length; i++) {
                var span = document.createElement("span");
                span.innerHTML = i+1;
                point.appendChild(span);
            }
            point.children[0].className = "current";
            console.log(point.offsetWidth);
            point.style.marginLeft = -point.offsetWidth / 2 + "px";



            //给小圆点添加事件
            var points = document.getElementsByTagName("span");
            var ul = lis[0].parentNode;
            var startNum = 0;
            var endNum = 0;
            var timer = null;
            for (var i = 0; i < points.length; i++) {
                points[i].index = i;
                points[i].onmouseover = function () {
                    clearInterval(timer);
                    var obj = this;
                    endNum = this.index * -500;
                    for (var j = 0; j < points.length; j++) {
                        points[j].className = "uncurrent";
                    }
                    this.className = "current";
                    timer = setInterval(function () {
                        startNum = startNum + (endNum - startNum)/10;
                        ul.style.left = startNum + "px";
                    },15);
                }
            }
        }
    </script>
</head>
<body>
    <div class="box">
        <div class="slider">
            <ul>
                <li><img src="images/01.jpg" alt=""></li>
                <li><img src="images/02.jpg" alt=""></li>
                <li><img src="images/03.jpg" alt=""></li>
                <li><img src="images/04.jpg" alt=""></li>
            </ul>
        </div>
        <div class="point"></div>
    </div>
</body>
</html>